<?php
/*
*	Plugin Name: Harmony!
*    	Plugin URI: Null
* 	Author: BBT
* 	Author URI: http://www.100steps.net
* 	Version: 1.1
*
*/

function profanity_comment_filter($content) {


	$f=fopen(ABSPATH."wp-content/plugins/ciyu.txt","r");
	$banned_contents=fread($f,30000);
	//echo $banned_contents;exit();
	fclose($f);
	$patterns = explode("|", $banned_contents);
	$finalremove=$content;
	$piece_front="";
	$piece_back="";
	$piece_replace="【文明用语】";

    for ($x=0; $x < count($patterns); $x++) {

    $safety=0;

        while(strstr(strtolower($finalremove),strtolower($patterns[$x]))) {
        # find & remove all occurrence
       
        $safety=$safety+1;
        if ($safety >= 100000) { break; }

        $occ=strpos(strtolower($finalremove),strtolower($patterns[$x]));
        $piece_front=substr($finalremove,0,$occ);
        $piece_back=substr($finalremove,($occ+strlen($patterns[$x])));
        $finalremove=$piece_front . $piece_replace . $piece_back;
        } # while
       
    }
	return $finalremove;
}
//include_once ABSPATH.'wp-includes/pluggable.php';
//$current_user=wp_get_current_user();
//if($current_user->roles['0']=="contributor")
if(1)
{
	add_filter('comment_text','profanity_comment_filter');
	add_filter('the_content','profanity_comment_filter');
	add_filter('the_title','profanity_comment_filter');
}
?>